using System;
using System.Collections.Generic;
using System.Text;

namespace RapidHDL
{

    public class PipelineBuffer : Component
    {

        public PipelineBus InputBus;
        public PipelineBus OutputBus;

        ClockComponent oClock;
        NodeVector nvReset;

        public Dictionary<int, PipelineBufferStage> Stages;

        public PipelineBuffer(Component poParentComponent, string psName, ClockComponent poClock, NodeVector pnvReset, int piWidth, int piDepth)
            : base(poParentComponent, psName)
        {
            InputBus = new PipelineBus(this, "input_bus", piWidth);
            OutputBus = new PipelineBus(this, "output_bus", piWidth);

            nvReset = pnvReset;
            oClock = poClock;
            Stages = new Dictionary<int, PipelineBufferStage>();

            for (int iStageIdx = 0; iStageIdx < piDepth; iStageIdx++)
            {
                PipelineBufferStage oStage = new PipelineBufferStage(this, "stage_" + iStageIdx.ToString(), poClock, pnvReset, piWidth);
                Stages.Add(iStageIdx, oStage);
                if (iStageIdx == 0)
                {
                    oStage.InputBus.Join(InputBus);
                }
                else
                {
                    PipelineBufferStage oLastStage = Stages[iStageIdx - 1];
                    oLastStage.OutputBus.Join(oStage.InputBus);
                }
                if (iStageIdx == piDepth - 1)
                {
                    oStage.OutputBus.Join(OutputBus);
                }
            }

        }

    }
}
